package com.example.bookappgraduation.models;

import android.os.Parcel;
import android.os.Parcelable;

public class Book implements Parcelable { // 实现 Parcelable 以便在 Intent 中传递
    //根据书籍查询 API (http://apis.juhe.cn/goodbook/query) 返回的 result.data 中的字段定义
    private String title;
    private String sub1; // 通常是作者和出版社
    private String sub2; // 通常是简介
    private String img;  // 图片 URL
    private String catalog; // 分类名
    private String catalog_id; // 分类ID
    private String reading; // 阅读信息，如字数
    private String online;  // 购买链接
    private String bytime; // 出版时间 (API中可能是这个字段)

    // 构造函数
    public Book(String title, String sub1, String sub2, String img, String catalog, String reading, String online, String bytime) {
        this.title = title;
        this.sub1 = sub1;
        this.sub2 = sub2;
        this.img = img;
        this.catalog = catalog;
        this.reading = reading;
        this.online = online;
        this.bytime = bytime;
    }

    // Getters
    public String getTitle() { return title; }
    public String getSub1() { return sub1; }
    public String getSub2() { return sub2; }
    public String getImg() { return img; }
    public String getCatalog() { return catalog; }
    public String getCatalog_id() { return catalog_id; }
    public String getReading() { return reading; }
    public String getOnline() { return online; }
    public String getBytime() { return bytime; }


    public void setCatalog_id(String catalog_id) { this.catalog_id = catalog_id; }


    // Parcelable 实现
    protected Book(Parcel in) {
        title = in.readString();
        sub1 = in.readString();
        sub2 = in.readString();
        img = in.readString();
        catalog = in.readString();
        catalog_id = in.readString();
        reading = in.readString();
        online = in.readString();
        bytime = in.readString();
    }

    public static final Creator<Book> CREATOR = new Creator<Book>() {
        @Override
        public Book createFromParcel(Parcel in) {
            return new Book(in);
        }

        @Override
        public Book[] newArray(int size) {
            return new Book[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(title);
        dest.writeString(sub1);
        dest.writeString(sub2);
        dest.writeString(img);
        dest.writeString(catalog);
        dest.writeString(catalog_id);
        dest.writeString(reading);
        dest.writeString(online);
        dest.writeString(bytime);
    }
}